<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use TCPDF;

class PdfEmail extends Mailable
{
    use Queueable, SerializesModels;

    protected $jobInfo;

    public function __construct($jobInfo)
    {
        $this->jobInfo = $jobInfo;
    }

    /**
     * Build the message.
     * @param $pdf
     * @return $this
     */
    public function build()
    {
        $position_custom_name = $this->jobInfo['position_custom_name'];
        $work_year            = $this->jobInfo['work_year'];
        if ($this->jobInfo['source'] == 1) {
            return $this->view('pdf')
                ->subject('移知招聘向您推荐了【' . $position_custom_name . '】 工作经验' . $work_year . '年')
                ->with(['job_info' => $this->jobInfo])
                ->attachData($this->jobInfo['path'], $this->jobInfo['user_name'].".pdf");
        } else {
            return $this->view('pdf')
                ->subject('移知招聘向您推荐了【' . $position_custom_name . '】 工作经验' . $work_year . '年')
                ->with(['job_info' => $this->jobInfo]);
        }
    }
}
